using UnityEngine;

#if UNITY_EDITOR
using UnityEditor;
#endif
using System;

[Serializable]
public class GT_NodeBase : ScriptableObject
{
    #region Public Varialbes
    public bool isSelected = false;
    public string nodeName;
    public Rect nodeRect;
    public GT_NodeGraph parentGraph;
    public NodeType nodeType;
    #endregion

    #region Protected Varuables
    protected GUISkin nodeSkin;
    #endregion

    #region SubClasses
    [Serializable]
    public class GT_NodeInput
    {
        public bool isOccupied = false;
        public GT_NodeBase inputNode;
    }

    [Serializable]
    public class GT_NodeOutput
    {
        public bool isOccupied = false;
    }
    #endregion

    #region Main Methods
    public virtual void InitNode()
    {

    }

    public virtual void UpdateNodes(Event e, Rect viewRect)
    {
        ProcessEvents(e, viewRect);
    }

#if UNITY_EDITOR
    public virtual void UpdateNodeGUI(Event e, Rect viewRect, GUISkin viewSkin)
    {
        ProcessEvents(e, viewRect);

        if (!isSelected)
        {
            GUI.Box(nodeRect, nodeName, viewSkin.GetStyle("NodeDefault"));
        }
        else
        {
            GUI.Box(nodeRect, nodeName, viewSkin.GetStyle("NodeSelected"));
        }

        EditorUtility.SetDirty(this);
    }

    public virtual void DrawNodeProperties()
    {

    }
#endif
    #endregion

    #region Utility Methods
    private void ProcessEvents(Event e, Rect viewRect)
    {
        if (isSelected)
        {
            if (viewRect.Contains(e.mousePosition))
            {
                if (e.type == EventType.MouseDrag)
                {
                    nodeRect.x += e.delta.x;
                    nodeRect.y += e.delta.y;
                }
            }
        }
    }
    #endregion
}
